#Load data
rm(list = setdiff(ls(), lsf.str()))
load("Study 1/Original Data (shareable)/Study1_dataverse_Denmark.RData")

#Openness
data$open1_rec<-6-data$v2010_del2_q36 
data$open2_rec<-6-data$v2010_del2_q10 
data$open3_rec<-6-data$v2010_del2_q40 
data$open4_rec<-6-data$v2010_del2_q13
data$open5_rec<-6-data$v2010_del2_q44
data$open6_rec<-6-data$v2010_del2_q5
data$open7<-data$v2010_del2_q16
data$open8<-data$v2010_del2_q35
data$open9<-data$v2010_del2_q48
data$open10<-data$v2010_del2_q56
data$open11<-data$v2010_del2_q29
data$open12<-data$v2010_del2_q32
data$open<-rowMeans(data.frame(data$open1_rec, data$open2_rec, data$open3_rec, data$open4_rec,  data$open5_rec,  data$open6_rec, data$open7,  data$open8, data$open9,  data$open10, data$open11,  data$open12), na.rm=T)

#CONSENTIOUSNESS
data$con1_rec<-6-data$v2010_del2_q27 
data$con2_rec<-6-data$v2010_del2_q18 
data$con3_rec<-6-data$v2010_del2_q37 
data$con4_rec<-6-data$v2010_del2_q11
data$con5_rec<-6-data$v2010_del2_q31
data$con6<-data$v2010_del2_q1
data$con7<-data$v2010_del2_q50
data$con8<-data$v2010_del2_q12
data$con9<-data$v2010_del2_q30
data$con10<-data$v2010_del2_q23
data$con11<-data$v2010_del2_q14
data$con12<-data$v2010_del2_q33
data$con<-rowMeans(data.frame(data$con1_rec, data$con2_rec, data$con3_rec, data$con4_rec, data$con5_rec, data$con6, data$con7, data$con8, data$con9, data$con10, data$con11, data$con12), na.rm=T)

#EXTRAVERSION
data$ext1_rec<-6-data$v2010_del2_q28
data$ext2_rec<-6-data$v2010_del2_q55
data$ext3_rec<-6-data$v2010_del2_q39
data$ext4<-data$v2010_del2_q34
data$ext5<-data$v2010_del2_q43
data$ext6<-data$v2010_del2_q7
data$ext7<-data$v2010_del2_q54
data$ext8<-data$v2010_del2_q57
data$ext9<-data$v2010_del2_q41
data$ext10<-data$v2010_del2_q59
data$ext11<-data$v2010_del2_q45
data$ext12<-data$v2010_del2_q60
data$ext<-rowMeans(data.frame(data$ext1_rec, data$ext2_rec, data$ext3_rec, data$ext4, data$ext5, data$ext6, data$ext7, data$ext8, data$ext9, data$ext10, data$ext11, data$ext12), na.rm=T)

#**AGREABLENES
data$agr1_rec<-6-data$v2010_del2_q17
data$agr2_rec<-6-data$v2010_del2_q8
data$agr3_rec<-6-data$v2010_del2_q49
data$agr4_rec<-6-data$v2010_del2_q2
data$agr5_rec<-6-data$v2010_del2_q20
data$agr6_rec<-6-data$v2010_del2_q51
data$agr7_rec<-6-data$v2010_del2_q4
data$agr8_rec<-6-data$v2010_del2_q22
data$agr9<-data$v2010_del2_q47
data$agr10<-data$v2010_del2_q3
data$agr11<-data$v2010_del2_q25
data$agr12<-data$v2010_del2_q46
data$agre<-rowMeans(data.frame(data$agr1_rec, data$agr2_rec, data$agr3_rec, data$agr4_rec, data$agr5_rec, data$agr6_rec, data$agr7_rec, data$agr8_rec, data$agr9, data$agr10, data$agr11, data$agr12), na.rm=T)

#**NEUROTISM
data$neu1_rec<-6-data$v2010_del2_q15
data$neu2_rec<-6-data$v2010_del2_q6
data$neu3_rec<-6-data$v2010_del2_q19
data$neu4_rec<-6-data$v2010_del2_q58
data$neu5<-data$v2010_del2_q26
data$neu6<-data$v2010_del2_q53
data$neu7<-data$v2010_del2_q9
data$neu8<-data$v2010_del2_q21
data$neu9<-data$v2010_del2_q38
data$neu10<-data$v2010_del2_q52
data$neu11<-data$v2010_del2_q24
data$neu12<-data$v2010_del2_q42
data$neu<-rowMeans(data.frame(data$neu1_rec, data$neu2_rec, data$neu3_rec, data$neu4_rec, data$neu5, data$neu6, data$neu7, data$neu8, data$neu9, data$neu10, data$neu11, data$neu12), na.rm=T)

#Household income
data$income<-data$v2010_husindkom
data$income<-car::recode(data$income, "12=NA")
data$income<-zero1(data$income)
data$income[is.na(data$income)==TRUE]=2

#Household missing
data$income_missing<-ifelse(data$income==2,1,0)

#Female
data$female<-ifelse(data$v2010_koen==2,1,0)

#Age
data$age<-data$v2010_alder

#education: 1=primary school; 2=vocational; 3=upper secondary; 4=professional; 5=bachelor or higher
data$v2010_education<-data$v2010_sidstuddands
data$v2010_education<-car::recode(data$v2010_education, "2=3; 4=2; 5=2;6=4;7=5;8=5;9=5")


data$v2010_edu2<-ifelse(data$v2010_education==2, 1,0)
data$v2010_edu3<-ifelse(data$v2010_education==3, 1,0)
data$v2010_edu4<-ifelse(data$v2010_education==4, 1,0)
data$v2010_edu5<-ifelse(data$v2010_education==5, 1,0)


#Vote for Danish people's party 2010
data$vote_populist10_intention<-ifelse(data$v2010_partivalg==15,1,0)

#Vote for Danish people's party 2011: intention
data$vote_populist11_intention<-ifelse(data$v2011_partivalg==15,1,0)

#Vote for Danish people's party in 2011 election
data$vote_populist11_choice<-ifelse(data$v2011_stemte_fv011==15,1,0)

#multinomial
data$vote_populist10_intention_multinom<-car::recode(data$v2010_partivalg, "15=1; 1=6; 2=5; 6=7; 10=9; 22=2; 24=4;28=8; 30=9; 32=9; 33=9; 34=9; 35=9")
#multinomial: government (Venstre/Konservative) vs. opposition (other parties)
data$vote_populist10_intention_govopp<-car::recode(data$vote_populist10_intention_multinom, "3=2; 4=3; 5=3; 6=3; 7=3; 8=3; 9=NA")
data$vote_populist10_intention_govopp<-as.factor(data$vote_populist10_intention_govopp)
levels(data$vote_populist10_intention_govopp) <- c("DPP","Government","Opposition")
data$vote_populist10_intention_govopp <- relevel(data$vote_populist10_intention_govopp, ref = "DPP")

#Economic conservatism -------------
data$econ1<-car::recode(data$v2010_q62_1, "5=NA") # High income earners do not pay enough taxes
data$econ2<-car::recode(data$v2010_q62_2, "5=NA") #Income inequality is too great in this country - the greatest pay raise should be given to low income people
data$econ_cons<-rowMeans(data.frame(data$econ1, data$econ2),na.rm=T)

#Social ideology--------------
data$v2010_q62_3_rec<- 5-car::recode(data$v2010_q62_3, "5=NA")
data$v2010_q62_4_rec<- 5-car::recode(data$v2010_q62_4, "5=NA")
data$v2010_q62_6_rec<- 5-car::recode(data$v2010_q62_6, "5=NA")
data$v2010_q62_5_4point<-car::recode(data$v2010_q62_5, "5=NA")
data$v2010_q62_7_4point<-car::recode(data$v2010_q62_7, "5=NA")
data$v2010_q62_8_4point<-car::recode(data$v2010_q62_8, "5=NA")
data$v2010_q62_10_4point<-car::recode(data$v2010_q62_10, "5=NA")
data$social<-rowMeans(data.frame(data$v2010_q62_3_rec, data$v2010_q62_4_rec, data$v2010_q62_5_4point, data$v2010_q62_6_rec, data$v2010_q62_7_4point, data$v2010_q62_8_4point, data$v2010_q62_10_4point), na.rm=T)

#cynicism
data$cyn1<- 4-car::recode(data$v2010_re_q68_1, "5=NA")
data$cyn2<- 4-car::recode(data$v2010_re_q68_2, "5=NA")
data$cyn3<- 4-car::recode(data$v2010_re_q68_3, "5=NA")
data$cynicism<- rowMeans(data.frame(data$cyn1, data$cyn2, data$cyn3), na.rm=T)

#vote in Danish election of 2011
data$didnotvote<-ifelse(data$v2011_fv11_01==1,0,1)

#populist, other, did not vote--------
data$populist_other_not<- data$vote_populist11_choice
data$populist_other_not[data$didnotvote==1]=2

save(data, file="Study 1/Altered Data/Study1_Denmark.RData")
